package doraemon

import (
	"bytes"
	"net/http"
)

// HttpGet 向目标 url 发起 http get 请求
func HttpGet(url string, params map[string]string) (*http.Response, error) {
	if len(params) > 0 {
		buf := bytes.NewBuffer([]byte(url))
		buf.WriteByte('?')
		for k, v := range params {
			buf.WriteString(k)
			buf.WriteByte('=')
			buf.WriteString(v)
			buf.WriteByte('&')
		}
		url = buf.String()[:buf.Len()-1]
	}

	return http.Get(url)
}
